<?php
    /**
     * Created by PhpStorm.
     * 版权所有: 2019~2022 [ hhygyl ]
     * Date: 2019/7/16-10:56
     * Link: http://luckyadmin.luckyhhy.cn
     * FileName: AdminLog.php
     * Keys: ctrl+alt+L/ctrl+s(代码格式化) ctrl+J(代码提示) ctrl+R(替换)ALT+INSERT(生成代码(如GET,SET方法,构造函数等) , 光标在类中才生效)
     * CTRL+ALT+O (优化导入的类和包 需要配置) SHIFT+F2(高亮错误或警告快速定位错误)
     * CTRL+SHIFT+Z(代码向前) CTRL+SHIFT+/ (块状注释) ctrl+shift+enter(智能完善代码 如if())
     *
     **************************************************************
     *                                                            *
     *   .=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-.       *
     *    |                     ______                     |      *
     *    |                  .-"      "-.                  |      *
     *    |                 /            \                 |      *
     *    |     _          |              |          _     |      *
     *    |    ( \         |,  .-.  .-.  ,|         / )    |      *
     *    |     > "=._     | )(__/  \__)( |     _.=" <     |      *
     *    |    (_/"=._"=._ |/     /\     \| _.="_.="\_)    |      *
     *    |           "=._"(_     ^^     _)"_.="           |      *
     *    |               "=\__|IIIIII|__/="               |      *
     *    |              _.="| \IIIIII/ |"=._              |      *
     *    |    _     _.="_.="\          /"=._"=._     _    |      *
     *    |   ( \_.="_.="     `--------`     "=._"=._/ )   |      *
     *    |    > _.="                            "=._ <    |      *
     *    |   (_/                                    \_)   |      *
     *    |                                                |      *
     *    '-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-='      *
     *                                                            *
     *                    JUST FIND YOUR BUG !                    *
     **************************************************************
     *
     */

    namespace app\admin\controller;


    use service\UtilService;
    use think\Exception;

    class AdminLog extends SystemBase
    {

        protected $admin_log;
        protected function _initialize()
        {
            parent::_initialize(); // TODO: Change the autogenerated stub
            $this->admin_log=new \app\admin\model\AdminLog();
        }


        /**
         * @return mixed
         * @author: hhygyl <hhygyl520@qq.com>
         * @name: index
         * @describe:操作日志
         */
        public function index(){

            if($this->request->isAjax()) {
                $param = $this->request->param();//接收参数
                $param['type']=2;//操作日志
                /**
                 * 返回获取的分页数据
                 */
                return $this->admin_log->GetAdminLogDataPage($param);
            }

            return $this->fetch();

        }


        /**
         * @return mixed
         * @author: hhygyl <hhygyl520@qq.com>
         * @name: login_log
         * @describe:登录日志
         */
        public function login_log(){

            if($this->request->isAjax()) {
                $param = $this->request->param();//接收参数
                $param['type']=1;//操作日志
                /**
                 * 返回获取的分页数据
                 */
                return $this->admin_log->GetAdminLogDataPage($param);
            }

            return $this->fetch();
        }



        /**
         * @author: hhygyl <hhygyl520@qq.com>
         * @name: delete
         * @describe:删除日志
         */
        public function delete(){

            if($this->request->isAjax()){
               
                $ids=$this->request->post("ids");
                return $this->DeleteData("admin_log",$ids);
            }
        }



        /**
         * @author: hhygyl <hhygyl520@qq.com>
         * @name: clear_all
         * @describe:清空日志
         */
        public function clear_all(){
            if($this->request->isAjax()){
             
                $type=$this->request->post("type");
                try{
                   $res=db("admin_log")->where("type",$type)->delete();
                    if($res) {
                        $this->success("清空成功");
                    }
                    else {
                        $this->error("清空失败");
                    }
                }catch (Exception $exception){

                    $this->error($exception->getMessage());
                }
            }
        }

    }